package cn.starrysky.hrm.service.impl;

import cn.starrysky.hrm.domain.Employee;
import cn.starrysky.hrm.domain.Tenant;
import cn.starrysky.hrm.mapper.EmployeeMapper;
import cn.starrysky.hrm.mapper.TenantMapper;
import cn.starrysky.hrm.service.IEmployeeService;
import cn.starrysky.hrm.util.AjaxResult;
import cn.starrysky.hrm.vo.UserContext;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author starrysky
 * @since 2021-03-02
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private TenantMapper tenantMapper;
    @Override
    public AjaxResult selectByLoginId(Long loginId) {
        Employee employee=employeeMapper.selectByLoginId(loginId);
        //查找机构
        Tenant tenant = tenantMapper.selectById(employee.getTenantId());
        UserContext userContext = new UserContext(employee.getId(), employee.getUsername(), tenant.getId(), tenant.getCompanyName());
        //json字符串
        return AjaxResult.me().setResultObj(JSON.toJSONString(userContext));
    }
}
